//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;
using Eas.WebCrawler.Interfaces;

namespace Eas.WebCrawler.Test.Scenario {
    public class LogTraceAction : NMock2.IAction {
        bool _Fail;
        public LogTraceAction() { _Fail = false; }
        public LogTraceAction(bool fail) {
            _Fail = fail;
        }

        public static List<string> traces = new List<string>();
        #region IInvokable Members

        public void Invoke(NMock2.Monitoring.Invocation invocation) {

            string trace = ((ProcessingStateMessageEventArgs)invocation.Parameters[1]).Message;
            if (_Fail && trace.IndexOf("Transitioned from") >= 0) {
                _Fail = false;
                throw new System.Exception("Test Injected Error");
            }
            //System.Diagnostics.Trace.WriteLine(trace);
            traces.Add(trace);
        }

        #endregion

        #region ISelfDescribing Members

        public void DescribeTo(System.IO.TextWriter writer) {
            writer.WriteLine("Trace Handler");
        }

        #endregion
    }
}
